<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view' );
class PropertiesViewProperties extends JView
{
	function display($tpl = null)
	{
		$user =& JFactory::getUser();
		global $mainframe;


		$task = JRequest::getVar('task');
		$component = JComponentHelper::getComponent( 'com_properties' );
		$params = new JParameter( $component->params );

		switch ($task){
			case 'search' :
				$items		= & $this->get( 'DataSearch');
				$pagination =& $this->get('PaginationSearch');

				break;
			case 'agentlisting' :
				$DataAgent= & $this->get( 'DataAgent');
				$this->assignRef('DataAgent',		$DataAgent);
				$items		= & $this->get( 'DataAgentListing');
				$pagination =& $this->get('PaginationAgentListing');
				$noShow['MostrarCarousel']=TRUE;
				$noShow['MostrarBuscar']=TRUE;
				$this->assignRef('noShow',		$noShow);
				break;
				/*case 'viewshortlist' :
				 $items		= & $this->get( 'DataShortList');
				 $pagination =& $this->get('PaginationShortList');
				 break;*/


			default :
				if(!JRequest::getVar('layout'))
				{
					$items		= & $this->get( 'Data');
					$pagination =& $this->get('Pagination');
				}
				break;
		}

		$list = JRequest::getVar('list');
		if(JRequest::getVar('layout')=='default_print' )
		{
			if(JRequest::getVar('ShortList')){

				$items		= & $this->get( 'DataShortList');
				$pagination =& $this->get('PaginationShortList');


			}
			elseif($list=='search'){
				$items		= & $this->get( 'DataSearch');
				$pagination =& $this->get('PaginationSearch');
			}else{
				$items		= & $this->get( 'Data');
				$pagination =& $this->get('Pagination');
			}


		}



		$itemsBuscar		= & $this->get( 'DataBuscar');
		$Last10Products = & $this->get('Last10Products');
		$Itemid =& $this->get('Itemid');

		$this->assignRef('Itemid',		$Itemid);
		$this->assignRef('items',		$items);
		$this->assignRef('itemsBuscar',		$itemsBuscar);
		$this->assignRef('pagination', $pagination);
		$this->assignRef('Last10Products',		$Last10Products);


		if(JRequest::getVar('layout')=='shortlist')
		{
			if(!$user->id){

				$Itemid=JRequest::getVar('Itemid');
				$Retornar='index.php?option=com_properties&view=panel&layout=myprofile&Itemid='.$Itemid;
				$url = base64_encode($Retornar);
				$link = 'index.php?option=com_properties&view=panel&task=login&return='.$url ;
				$msg = JText::_( 'Registered Users only can access' );
				$mainframe->Redirect($link, $msg);


			}


			$itemsShortList		= & $this->get( 'DataShortList');
			$paginationShortList =& $this->get('PaginationShortList');
			$this->assignRef('items',		$itemsShortList);
			$this->assignRef('pagination', $paginationShortList);
		}



		/////fuck Jommfish////
		//$NameProduct			=& $this->NameProduct();
		$NameCategory			= $this->NameCategory();
		$NameType				=& $this->NameType();
		$NameCountry			= $this->NameCountry();
		$NameState				=& $this->NameState();
		$NameLocality			=& $this->NameLocality();


		//$this->assignRef('NameProduct',		$NameProduct);
		$this->assignRef('NameCategory',	$NameCategory);
		$this->assignRef('NameType',		$NameType);
		$this->assignRef('NameCountry',		$NameCountry);
		$this->assignRef('NameState',		$NameState);
		$this->assignRef('NameLocality',	$NameLocality);

		//$ThisAgent				=& $this->ThisAgent();
		//$this->assignRef('ThisAgent',	$ThisAgent);
		///pls change/////

		parent::display($layout);


	}

	/*
	 function ThisAgent()
	 {
	 $db 	=& JFactory::getDBO();
	 $query = 'SELECT * FROM #__properties_profiles ORDER BY id';
	 $db->setQuery($query);
		$Agents = $db->loadObjectList();

		foreach ($Agents as $row) :
		$Agent[$row->mid] = $row;
		endforeach;

		return $Agent;
		}
		*/

	function NameCategory()
	{
		$db 	=& JFactory::getDBO();
		$query = 'SELECT * FROM #__properties_category WHERE published = 1 ORDER BY id';
		$db->setQuery($query);
		$Categories = $db->loadObjectList();

		foreach ($Categories as $row) :
		$Category[$row->id] = $row->name;
		endforeach;

		return $Category;
	}

	function NameType()
	{
		$db 	=& JFactory::getDBO();
		$query = 'SELECT * FROM #__properties_type WHERE published = 1 ORDER BY name';
		$db->setQuery($query);
		$Types = $db->loadObjectList();

		foreach ($Types as $row) :
		$Type[$row->id] = $row->name;
		endforeach;

			
		return $Type;
	}

	function NameCountry()
	{
		$db 	=& JFactory::getDBO();
		$query = 'SELECT * FROM #__properties_country WHERE published = 1 ORDER BY name';
		$db->setQuery($query);
		$Countries = $db->loadObjectList();
			
		foreach ($Countries as $row) :
		$Country[$row->id] = $row->name;
		endforeach;

		return $Country;
	}
	function NameState()
	{
		$db 	=& JFactory::getDBO();
		$query = 'SELECT * FROM #__properties_state WHERE published = 1 ORDER BY name';
		$db->setQuery($query);
		$States = $db->loadObjectList();

		foreach ($States as $row) :
		$State[$row->id] = $row->name;
		endforeach;

		return $State;
	}
	function NameLocality()
	{
		$db 	=& JFactory::getDBO();
		$query = 'SELECT * FROM #__properties_locality WHERE published = 1 ORDER BY name';
		$db->setQuery($query);
		$Localities = $db->loadObjectList();

		foreach ($Localities as $row) :
		$Locality[$row->id] = $row->name;
		endforeach;

		return $Locality;
	}
}